const db = require('../mysql')

// 获取课程类别
exports.getCate = (req, res) => {
    const getCateSql = 'SELECT * FROM class_category'
    db.query(getCateSql, (err, result) => {
        if (err) return res.cc(err)
        res.send({
            status: 200,
            data: result,
            message: '获取分类成功'
        })
    })

}

// 获取课程
exports.getClasses = (req, res) => {
    let cate_id = null
    if (Object.keys(req.query).length === 0) {
        cate_id = 2001
    } else {
        cate_id = req.query.cate_id
    }
    const getClassSql = 'SELECT * FROM classes WHERE cate_id=?'
    db.query(getClassSql,cate_id, (err, result) => {
        if (err) return res.cc(err)
        res.send({
            status: 200,
            data: result,
            message: '获取分类成功'
        })
    })

}